<?php
namespace app\home\controller;

use think\Controller;
use think\Db;
use think\Exception;
use think\Request;

class Worker extends Controller
{
//    public function __construct(Request $request = null)
//    {
//        parent::__construct($request);
//        session('uid', 58);
//
//    }


    public function index()
    {

        // $data = Db::name('user_worker')->where('mark', 1)->select();
        // $this->assign('data', $data);
        return $this->fetch('index');
    }

    //筛选
    public function shaixuan(Request $request)
    {
        if ($request->isAjax()) {
            $request = $request->param('type');
            $data = Db::name('user_worker')->where('type', $request)->select();// 多条数据要进行遍历，用select
            return json($data);
        }
    }

    //显示弹窗数据
    public function getgrdata(Request $request)
    {

        if ($request->isAjax()) {
            $request = $request->param('tcd');
            $data = Db::name('user_worker')->where('id', $request)->find(); //一条数据用
            return json($data);
        }
    }

    //下拉加载数据
    public function loaddata(Request $request)
    {
        if ($request->isAjax()) {


            $status[0] = '禁用';
            $status[1] = '正常';
            $page = input('page') ? input('page') : 1;
            $limit = input('limit') ? input('limit') : 10;


            $res = Db::name('user_worker')->page($page, $limit)->select();
            $qiniu_config = cmf_get_option('qiniu');
            // 七牛样式处理
            $q_thumb = "?imageMogr2/auto-orient/thumbnail/!60x120r/gravity/Center/crop/80x120/quality/100/interlace/0";
            $us = Db::name('user');
            foreach ($res as $index => $re) {
                $res[$index]['avatar2'] = $qiniu_config['domain'] . '/' . $re['avatar2'] . $q_thumb;
                $res[$index]['truename'] = $us->where('id', $re['uid'])->value('truename');

            }

            return json(['code' => 1, 'msg' => 'ok', 'count' => count($res), 'data' => $res]);
        }
    }


    //我的钱包
    public function mywallet(Request $request)
    {
        $uid = session('uid');
        //登录成功后就能获取用户id
//        Db::startTrans();
        // $salary = Db::name('user')->insertGetId($uid);
        $salary = Db::name('user')->where('id', $uid)->find();
        if ($salary) {
            $this->assign("salary", $salary);
            return $this->fetch('my_wallet');
        }
        return $this->fetch('my_wallet');
    }

    //交易记录
    public function mytransactionrecord()
    {
        $uid = session('uid');
        $record = Db::name('record')->where('worker_id', $uid)->select();
        //var_dump($record).die();
//        $re=(int)$record[0]["record"];
//        var_dump($re).die();
        $this->assign("record", $record);
        return $this->fetch('my_transaction_record');
    }

    //银行卡
    public function mycard(Request $request)
    {
        $uid = session('uid');
        $cardtype = Db::name('bankcard')->where('worker_id', $uid)->select();
        // var_dump($cardtype).die();
        foreach ($cardtype as $index => $re) {
            $cardtype[$index]['cardnumber'] = substr($re['cardnumber'], -4);
        }
        $this->assign("cardtype", $cardtype);
        return $this->fetch('my_card');
    }

    //添加银行卡
    public function myaddcard()
    {
        return $this->fetch('my_addcard');
    }

    public function add()
    {
        $uid = session('uid');
        //获取表单提交数据
        $data = input();
        $name = $data["name"];
        $num = $data["cardnumber"];
        $type = $data["card"];
        $p= Db::name('user')->where('id',$uid)->find();
        $mobile=$p["phone"];
        if ($name == "" || $num == "" || $type == "" || $type == 0) {
            $this->error("添加失败");
            $this->redirect('home/worker/mycard');
        } else if (Db::name('bankcard')->insert(['type' => $type, 'worker_id' => $uid, 'cardnumber' => $num, 'name' => $name])) {
            $this->redirect('home/worker/mycard');
        } else {
            $this->error("添加失败");
        }
//        $mobile_code = $data['code'];
//        if (!$mobile || !$mobile_code) {
//            $this->error('请输入手机号或验证码');
//        }
//        $res = Db::name('sms_code')->where('phone', $mobile)->find();
//
//        if ($res) {
//            //是否过期
//            if ($res['createtime'] < (time() - 60 * 10)) {
//                $this->error('验证码过期');
//            }
//            if ($res['code'] != $mobile_code) {
//                $this->error('验证码错误');
//            }
//            $user = Db::name('user')->where('phone', $mobile)->find();
//            session('uid', $user['id']);
//            session('user', $user);
//            $this->success('认证成功');
//
//        } else {
//            $this->error('验证码错误2');
//        }


//         $cardtype = Db::name('bankcard')->where('worker_id',1)->select();
//         var_dump($cardtype).die();
//         $this->assign("cardtype",$cardtype);


        return $this->fetch('my_card');

    }

    public function sms()
    {
        $uid = session('uid');
        $p= Db::name('user')->where('id',$uid)->find();
        $phone=$p["phone"];


        if (!isMobileNum($phone)) {
            $this->error('手机号不正确');
        };

        // 判断是否存在
        $res = Db::name('user')->where('phone', $phone)
            ->field('id')
            ->find();
        if (!$res) {
            $this->error('手机号未认证');
        }

        $res = sendSms($phone);
        if ($res == 1) {
            $this->success('发送成功');
        }
        $this->error('发送失败');
    }


    //提现
    public function myonlinemoney(Request $request)
    {
        $uid = session('uid');
//        $id=input('id');
        $cardid = input('cardid');
        $flag = input('flag');
        if ($flag == '1') {
            $card = Db::name('bankcard')->where('worker_id', $uid)->find();
            $card['cardnumber'] = substr($card['cardnumber'], -4);
        } else if ($flag == '2') {
            $card = Db::name('bankcard')->where('id', $cardid)->find();
//            var_dump($card).die();
            $card['cardnumber'] = substr($card['cardnumber'], -4);

        }
        $this->assign("card", $card);
        // $cid=json_encode($card);
        // $salary = Db::name('user')->insertGetId($uid);
        $salary = Db::name('user')->where('id', $uid)->find();
        $this->assign("salary", $salary);

        return $this->fetch('my_online_money');
    }

    //提现所要实现的插入数据
    public function tixian()
    {
//        Db::name('cash_manager')->where('id', 1)->insert( ['jine'=>$_POST["jine"]]);
//        return $this->fetch('my_wallet');
//        //用户表中查找工人
//        $salary = Db::name('user')->where('id', $uid)->find();

//        $information= Db::name('bankcard')->where('id' ,$data['cardid'])->find();
//        $rzh = Db::name('user')->where('uid', $uid)->find();
//       var_dump($data['jine']).die();
//        $data = input('');
        if (isset($_POST)) {

            Db::startTrans();
            try {

                $data = input('');
                $data['create_time'] = time();
                //     var_dump($data['jine']);
                //用户id
                $uid = session('uid');
                //   $uid = Db::name('cash_manager')->insertGetId($data);
                //工人表中查找认证号  $rzh['renzhenghao']
                $rzh = Db::name('user_worker')->where('uid', $uid)->find();

                //用户表中查找工人
                $salary = Db::name('user')->where('id', $uid)->find();
                //    var_dump($salary['money']);
                //获取工人选择的哪张银行卡的信息//在工人银行卡表中查找具体银行卡  $information['type']  $information['cardnumber']   $information['name']
                $information = Db::name('bankcard')->where('id', $data['cardid'])->find();
                $flag = true;
                if (!$salary) {
                    $msg = '该用户不存在';
                    $flag = false;
                }
                if ($salary['is_worker'] != '1') {
                    $msg = '该用户不是工人';
                    $flag = false;
                }

                if (!$data['jine']) {
                    $msg = '请填写金额';
                    $flag = false;
                }

                if ((int)$data['jine'] < 100 || ((int)$data['jine']) % 100 != 0) {
                    $msg = '取款金额不足100元，请去100的倍数';
                    $flag = false;
                }
                if ($data['jine'] > $salary['money']) {
                    $msg = '余额不足无法提现';
                    $flag = false;
                }

                if (!$information) {
                    $msg = '此银行卡不存在';
                    $flag = false;
                }

                if (!$rzh) {
                    $msg = '该工人不存在';
                    $flag = false;
                }

                if ($data['jine']) {
                    $salary['money'] = (int)$salary['money'] - (int)$data['jine'];
                    //账户余额变化
                    $jisuan = Db::name('user')->where('id', $uid)->update(['money' => $salary['money']]);
                    if (!$jisuan) {
                        $msg = '余额更新失败';
                        $flag = false;
                    }
                    $record = Db::name('record')->where('worker_id', $uid)->insert(['record' => -(int)($data['jine']), 'worker_id' => $uid]);
                    if (!$record) {
                        $msg = '插入交易记录失败';
                        $flag = false;

                    }
                }

                if (!$flag) {
                    // 事务回滚
                    Db::rollback();
                    $this->error($msg);
                }

                Db::name('cash_manager')
                    ->insert(['renzhenghao' => $rzh['renzhenghao'], 'name' => $information['name'], 'jine' => $data['jine'], 'bank_type' => $information['type'], 'cardnumber' => $information['cardnumber'], 'create_time' => $data['create_time'], 'status' => 0, 'uid' => $uid]);

                //事务提交
                Db::commit();
                $this->success('提现成功，请耐心等待');
            } catch (Exception $exception) {
                Db::rollback();
                $this->error('error');
            }

        }

    }

    //选择银行卡
    public function selectcard()
    {
        $uid = session('uid');
        $res = Db::name('bankcard')->where('worker_id', $uid)->select();
        foreach ($res as $index => $re) {
            $res[$index]['cardnumber'] = substr($re['cardnumber'], -4);
        }
//        dump($res);die;
        $this->assign("information", $res);
        return $this->fetch('my_selectcard');
    }

    //我的工作
    public function mywork(Request $request)
    {
//      if($this->request->isAjax()){
//          $page=$this->request->param("page");
//
//          $all=  Db::name('project')
//              ->page($page)
//              ->limit(5)
//              ->select();
//          return  json($all);
//      }
//       $m= $this->request->param('m');
//        var_dump($m).die();

//        if ($request->isAjax()) {
//            $status[0] = '禁用';
//            $status[1] = '正常';
//            $page = input('page') ? input('page') : 1;
//            $limit = input('limit') ? input('limit') : 5;
//
//            $res = Db::name('project')->page($page, $limit)->select();
////            $qiniu_config = cmf_get_option('qiniu');
////            // 七牛样式处理
////            $q_thumb = "?imageMogr2/auto-orient/thumbnail/!60x120r/gravity/Center/crop/80x120/quality/100/interlace/0";
////
////            foreach ($res as $index => $re) {
////                $res[$index]['avatar2'] = $qiniu_config['domain'] . '/' . $re['avatar2'] . $q_thumb;
////            }
////            var_dump($request->param('flag'));
//            return json(['code' => 1, 'msg' => 'ok', 'count' => count($res), 'data' => $res]);
//        }
        $uid = session('uid');
        $sy=Db::name('project_ys_record')->where('stage_id',$uid)->select();
        if ($request->isAjax()) {
            $status[0] = '禁用';
            $status[1] = '正常';

            $page = input('page') ? input('page') : 1;
            $limit = input('limit') ? input('limit') : 10;
            $flag = $this->request->param('flag');
            if ($flag == '1') {
               // $res = Db::name('project_stage')->where('status',1)->page($page, $limit)->select();

                $res = Db::name('project_stage')
                    ->join('iw_project', 'iw_project.id=iw_project_stage.project_id')
                    ->join('iw_project_client', 'iw_project_client.project_id=iw_project_stage.project_id')
                    ->field('iw_project_client.name,iw_project_stage.title,iw_project_stage.start_time,iw_project_stage.id,iw_project.project_picture')
                    ->where('iw_project_stage.status', 1)
                    ->where('iw_project_stage.is_delete', 0)
                    ->page($page, $limit)
                    ->select();
                $qiniu_config = cmf_get_option('qiniu');
                // 七牛样式处理
                $q_thumb = "?imageMogr2/auto-orient/thumbnail/!60x120r/gravity/Center/crop/120x120/quality/100/interlace/0";
                foreach ($res as $index => $re) {
                    $res[$index]['project_picture'] = $qiniu_config['domain'] . '/' . $re['project_picture'] . $q_thumb;
                }
                return json(['code' => 1, 'msg' => 'ok', 'count' => count($res), 'data' => $res]);
            } else if ($flag == '2') {
               // $res = Db::name('project_stage')->where('status', 0)->page($page, $limit)->select();
       $qd=Db::name('sign_in')->where('worker_id',$uid)->find();
                $res['create_time'] = date('Y-m-d');
       $qd['create_time']=
                $res = Db::name('project_stage')
                    ->join('iw_project', 'iw_project.id=iw_project_stage.project_id')
                    ->join('iw_project_bid_record', 'iw_project_bid_record.stage_id=iw_project_stage.id')
                    ->join('iw_project_client', 'iw_project_client.project_id=iw_project_stage.project_id')
                    ->field('iw_project_client.name,iw_project_stage.title,iw_project_stage.start_time,iw_project_stage.id,iw_project.project_picture,iw_project_bid_record.worker_id as wkid')
                    ->where('iw_project_bid_record.status', 1)
                    ->where('iw_project_bid_record.worker_id',$uid)
                    ->page($page, $limit)
                    ->select();

                $qiniu_config = cmf_get_option('qiniu');
                // 七牛样式处理
                $q_thumb = "?imageMogr2/auto-orient/thumbnail/!60x120r/gravity/Center/crop/120x120/quality/100/interlace/0";
                $project_ys_record = Db::name('project_ys_record');
                foreach ($res as $index => $re) {
                    $res[$index]['project_picture'] = $qiniu_config['domain'] . '/' . $re['project_picture'] . $q_thumb;
                    $da_res=$project_ys_record
                        ->where('worker_id',$uid)
                        ->where('stage_id',$re['id'])
                        ->find();
                    $res[$index]['ys_status']=0;
                    if($da_res){
                        $res[$index]['ys_status']=$da_res['status'];
                    }

                }


                return json(['code' => 1, 'msg' => 'ok', 'count' => count($res), 'data' => $res]);
            } else if ($flag == '3') {
               // $res = Db::name('project_stage')->where('status', 2)->page($page, $limit)->select();

                $res = Db::name('project_stage')
                    ->join('iw_project', 'iw_project.id=iw_project_stage.project_id')
                    ->join('iw_project_bid_record', 'iw_project_bid_record.stage_id=iw_project_stage.id')
                    ->join('iw_project_client', 'iw_project_client.project_id=iw_project_stage.project_id')
                    ->field('iw_project_client.name,iw_project_stage.title,iw_project_stage.start_time,iw_project_stage.id,iw_project.project_picture')
                    ->where('iw_project_bid_record.status', 0)
                    ->where('iw_project_bid_record.worker_id',$uid)
                    ->page($page, $limit)
                    ->select();
                $qiniu_config = cmf_get_option('qiniu');
                // 七牛样式处理
                $q_thumb = "?imageMogr2/auto-orient/thumbnail/!60x120r/gravity/Center/crop/120x120/quality/100/interlace/0";
                foreach ($res as $index => $re) {
                    $res[$index]['project_picture'] = $qiniu_config['domain'] . '/' . $re['project_picture'] . $q_thumb;
                }
                return json(['code' => 1, 'msg' => 'ok', 'count' => count($res), 'data' => $res]);
            }  else {
                $res = Db::name('project_stage')
                    ->join('iw_project', 'iw_project.id=iw_project_stage.project_id')
                    ->join('iw_project_bid_record', 'iw_project_bid_record.stage_id=iw_project_stage.id')
                    ->join('iw_project_client', 'iw_project_client.project_id=iw_project_stage.project_id')
                    ->field('iw_project_client.name,iw_project_stage.title,iw_project_stage.start_time,iw_project_stage.id,iw_project.project_picture')
                    ->where('iw_project_bid_record.status', 0)
                    ->where('iw_project_bid_record.worker_id',$uid)
                    ->page($page, $limit)
                    ->select();
                $qiniu_config = cmf_get_option('qiniu');
                // 七牛样式处理
                $q_thumb = "?imageMogr2/auto-orient/thumbnail/!60x120r/gravity/Center/crop/120x120/quality/100/interlace/0";
                foreach ($res as $index => $re) {
                    $res[$index]['project_picture'] = $qiniu_config['domain'] . '/' . $re['project_picture'] . $q_thumb;
                }
                return json(['code' => 1, 'msg' => 'ok', 'count' => count($res), 'data' => $res]);

            }
        }

        $this->assign('sqbtn',$sy);
        return $this->fetch('my_work');
    }

    public function delete(){
        if (request()->isAjax()) {
            $data['stage_id'] = input('stage_id');
            $res=Db::name('project_stage')
                ->where('id',$data['stage_id'])
                ->update(['is_delete'=>1]);
            if ($res){
                $this->success('删除成功');
            }else {
                $this->error('删除失败');
            }
           }
        return $this->fetch('my_work');

        }
    //竞标
    public function myjb(Request $request)
    {
        $uid = session('uid');
        $sy=Db::name('project_ys_record')->where('stage_id',$uid)->select();
        if ($request->isAjax()) {
            $status[0] = '禁用';
            $status[1] = '正常';

            $page = input('page') ? input('page') : 1;
            $limit = input('limit') ? input('limit') : 10;

            $res = Db::name('project_stage')
                ->join('iw_project', 'iw_project.id=iw_project_stage.project_id')
                ->join('iw_project_client', 'iw_project_client.project_id=iw_project_stage.project_id')
                ->field('iw_project_client.name,iw_project_stage.title,iw_project_stage.start_time,iw_project_stage.id,iw_project.project_picture')
                ->where('iw_project_stage.status', 1)
                ->page($page, $limit)
                ->select();
            $qiniu_config = cmf_get_option('qiniu');
            // 七牛样式处理
            $q_thumb = "?imageMogr2/auto-orient/thumbnail/!60x120r/gravity/Center/crop/120x120/quality/100/interlace/0";
            foreach ($res as $index => $re) {
                $res[$index]['project_picture'] = $qiniu_config['domain'] . '/' . $re['project_picture'] . $q_thumb;
            }

            return json(['code' => 1, 'msg' => 'ok', 'count' => count($res), 'data' => $res]);
        }

        $this->assign('sqbtn',$sy);
        return $this->fetch('my_jb');
    }
    //搜索
    public  function  sousuo(){
        return  $this->fetch('wksousuo');
    }
    public function search(Request $request)
    {
        if ($request->isAjax()) {
            $page = input('page') ? input('page') : 1;
            $limit = input('limit') ? input('limit') : 10;
            $fenlei = $request->param('shuju');
            if($fenlei){
                $res = Db::name('project_stage')
                    ->join('iw_project', 'iw_project.id=iw_project_stage.project_id')
                    ->where([
                        'iw_project_stage.title'=>['like', '%' . $fenlei . '%']
                    ])
                    ->where('iw_project_stage.status', 1)
                    ->page($page, $limit)
                    ->select();

                if ($res) {
                    $qiniu_config = cmf_get_option('qiniu');
                    // 七牛样式处理
                    $q_thumb = "?imageMogr2/auto-orient/thumbnail/!60x120r/gravity/Center/crop/120x120/quality/100/interlace/0";
                    foreach ($res as $index => $re) {
                        $res[$index]['project_picture'] = $qiniu_config['domain'] . '/' . $re['project_picture'] . $q_thumb;
                    }
                    return json(['code' => 1, 'msg' => 'ok', 'count' => count($res), 'data' => $res]);
                }
            }
        }
    }
    //工人申请工作验收
    public function ys()
    {

        if (request()->isAjax()) {
            $uid = session('uid');
            $data = input('');
            $data['create_time'] = time();
            $data['status']=1;
            $data['stage_id']=input('stage_id');
            $data['worker_id']=$uid;

//       $re=  Db::name('user_worker')->where('uid',$uid)->find();
//       $worker_id=$re['id'];
//       $re1=Db::name('project_stage')->where('id',$stage_id)->find();
//       $jdname=$re1['title'];
//       $project_id=$re1['project_id'];

            if($data !=  '') {
                $res = Db::name('project_ys_record')->insertGetId($data);
             //  $res = Db::name('project_ys_record')->insert(['worker_id' => $uid, 'stage_id' => $stage_id, 'status' => 0, 'create_time' => $res['create_time']]);
                if ($res) {

                    $this->success('操作成功');
                } else {
                    $this->error('操作失败');
                }
            }

        }

    }
    public function signin(){
        if (request()->isAjax()) {
            $uid = session('uid');
            $data = input('');
            $data['create_time'] = time();
            $data['stage_id']=input('stage_id');
            $data['worker_id']=$uid;
            if($data !=  '') {
                $res = Db::name('sign_in')->insertGetId($data);
                if ($res) {

                    $this->success('操作成功');
                } else {
                    $this->error('操作失败');
                }
            }
        }
    }
    public function bid_detail(Request $request){
        if($request->isAjax()){
            $data=input("");
            $res=Db::name("project_bid_record")->insert($data);
            if($res){
                $this->success('操作成功');
            }
        }else{

            $uid = session('uid');
           // dump(session('user'));
            //dump($uid);
            //die();
            $sid=input('id');
//            dump($sid);
//            die();
            $f="";
            $qiniu_config = cmf_get_option('qiniu');
            $q_thumb="?imageMogr2/auto-orient/thumbnail/!60x120r/gravity/Center/crop/120x120/quality/100/interlace/0";
            $re=Db::name("project_bid_record")->where('worker_id',$uid)
                ->where('stage_id',$sid)
                ->find();
            if($re){

                if($re['status']==1){
                    $f="已同意竞标";
                }
                if($re['status']==2){
                    $f="已拒绝竞标";
                }
                if($re['status']==0){
                    $f="正在审核";
                }
            }
            else{

                $f="竞标";
            }

            $stage=Db::name('project_stage')->where('id',$sid)->find();

            $type=Db::name('project_worker_type')->where('stage_id', $sid)->select();
            $stage['type']=$type;

            $pro=Db::name('project')->where('id',$stage['project_id'])->find();

            $cli = Db::name('project_client')->field("name")->where('project_id', $pro['id'])->select();
            $pro["client"] = $cli;

            $pm=Db::name('user')->where('id',$pro['project_manager_id'])->find();
            if( !$pm['avatar']){
                $pm['avatar']="/static/images/photo.png";
            }else{
                $pm['avatar'] = $qiniu_config['domain'] . '/' . $pm['avatar'] . $q_thumb;
            }

            $am=Db::name('user')->where('id',$pro['customer_manager_id'])->find();
            if( !$am['avatar']){
                $am['avatar']="/static/images/photo.png";
            }else{
                $am['avatar'] = $qiniu_config['domain'] . '/' . $am['avatar'] . $q_thumb;
            }
            $ds=Db::name('user')->where('id',$pro['designer_id'])->find();
            if( !$ds['avatar']){
                $ds['avatar']="/static/images/photo.png";
            }else{
                $ds['avatar'] = $qiniu_config['domain'] . '/' . $ds['avatar'] . $q_thumb;
            }

            $qc=Db::name('user')->where('id',$pro['qualityl_id'])->find();
            if( !$qc['avatar']){
                $qc['avatar']="/static/images/photo.png";
            }else{
                $qc['avatar'] = $qiniu_config['domain'] . '/' . $qc['avatar'] . $q_thumb;
            }

            $res=Db::name('project_stage_material')->where('project_stage_id',$sid)->select();
            foreach ($res as $index => $re) {
                $m=Db::name('goods')->where('id',$re['goods_id'])->find();
                $res[$index]['name']=$m['name'];
            }
            $this->assign('pro',$pro);
            $this->assign('pm',$pm);
            $this->assign('am',$am);
            $this->assign('ds',$ds);
            $this->assign('qc',$qc);
            $this->assign('stage',$stage);
            $this->assign('res',$res);
            $this->assign('f',$f);
            $this->assign("uid",$uid);
            $this->assign('sid',$sid);
            return $this->fetch();
        }


    }

}



//                $res = Db::name('project_stage')->where('status' ,0)->select();
//                foreach ($res as $index => $r) {
//                    $kh=Db::name('project')->where('id',$r['project_id'])->find();
//                    $res[$index]['kh']=$kh['client'];
//                    $res[$index]['client']=Db::name('project');
//
//                }
//        var_dump($res);












//
//
//$uid = session('uid');
////获取表单提交数据
//$data = input();
//$name = $data["name"];
//$num = $data["cardnumber"];
//$type = $data["card"];
//$p= Db::name('user')->where('id',$uid)->find();
//$mobile=$p["phone"];
//$mobile_code = $data['code'];
//$res = Db::name('sms_code')->where('phone', $mobile)->find();
//if (!$mobile || !$mobile_code  ||  $name == "" || $num == "" || $type == "" || $type == 0) {
//    $this->error('请将信息填写完整');
//    $this->redirect('home/worker/mycard');
//}
//
//
//else if(   $res  && Db::name('bankcard')->insert(['type' => $type, 'worker_id' => $uid, 'cardnumber' => $num, 'name' => $name])) {
//
//    //是否过期
//    if ($res['createtime'] < (time() - 60 * 10)) {
//        $this->error('验证码过期');
//    }
//    if ($res['code'] != $mobile_code) {
//        $this->error('验证码错误');
//    }
//    $user = Db::name('user')->where('phone', $mobile)->find();
//    session('uid', $user['id']);
//    session('user', $user);
//    $this->success('认证成功');
//    $this->redirect('home/worker/mycard');
//}else {
//    $this->error('验证码错误2');
//}

